package com.zzw.controller;

import com.zzw.entity.PageResult;
import com.zzw.entity.Result;
import com.zzw.message.MessageConstant;
import com.github.pagehelper.PageInfo;
import com.zzw.pojo.Oil;
import com.zzw.service.OilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/oil")
public class OilController {
    @Autowired
    private OilService oilService;

    @GetMapping("/findAll")
    public Result findAll(){
        try {
            List<Oil> list = oilService.findAll();
            return new Result(true,MessageConstant.QUERY_OIL_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_OIL_FAIL);
        }
    }


    @PostMapping("/add")
    public Result addOil(@RequestBody Oil oil){
        try {
            oilService.addOil(oil);
            return new Result(true, MessageConstant.ADD_OIL_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false, MessageConstant.ADD_OIL_FAIL);
    }
}
